﻿function OrderValid(clientName, clientEmail, clientPhone, clientAddress)
{
    var rName = new RegExp("[0-9a-zA-Z]");
    if (!rName.exec(clientName))
    {
        return 10;
    }

    var rEmail = new RegExp("[0-9a-zA-Z]");
    if (!rEmail.exec(clientEmail))
    {
        return 20;
    }

    var rEmailValid = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$");
    if (!rEmailValid.test(clientEmail) || clientEmail.length > 100)
    {
        return 21;
    }

    var rPhone = new RegExp("[0-9a-zA-Z]");
    if (!rPhone.exec(clientPhone))
    {
        return 30;
    }

    var rPhoneValid = new RegExp("^[0-9]{10,15}$");
    if (!rPhoneValid.exec(clientPhone))
    {
        return 31;
    }

    var rAddress = RegExp("[0-9a-zA-Z]");
    if (!rAddress.exec(clientAddress))
    {
        return 40;
    }

    return 1;
}